package com.kd.juhaowan.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;


import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.hjq.toast.ToastUtils;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.ForgetPwdApi;
import com.kd.juhaowan.http.model.FollowResult;
import com.kd.juhaowan.http.model.HttpData;

import butterknife.BindView;
import butterknife.OnClick;

public class ForgetFindActivity extends BaseActivity {





    @BindView(R.id.login_account_account)
    EditText registAccount;
    @BindView(R.id.login_account_pwd)
    EditText registPWD;


    @BindView(R.id.login_account_tip)
    TextView tipText;

    private String username,phone, token;

    @Override
    protected void reInitDate() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_account_login);
        username = getIntent().getStringExtra("username");
        phone = getIntent().getStringExtra("phone");
        token = getIntent().getStringExtra("token");
        tipText.setText("您当前操作的账号是"+username);
    }

    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_forget_find;
    }

//    @OnClick(R.id.login_account_forget)
//    public void onForgetClick(View view){
//
//    }

    @OnClick(R.id.login_confirm)
    public void onLoginClick(View view){
        String pwd = registAccount.getText().toString().trim();
        String pwdConfirm = registPWD.getText().toString().trim();
        if(TextUtils.isEmpty(pwd)){
            ToastUtils.show("请输入新密码");
        }else if(TextUtils.isEmpty(pwdConfirm)){
            ToastUtils.show("请输入确认密码");
        }else if(!pwd.equals(pwdConfirm)){
            ToastUtils.show("两次密码不一致");
        } else {
            EasyHttp.post(this).api(new ForgetPwdApi(username,token,pwd)).request(new HttpCallbackProxy<HttpData<FollowResult>>(this){
                @Override
                public void onHttpSuccess(HttpData<FollowResult> result, boolean cache) {
                    super.onHttpSuccess(result, cache);
                    ToastUtils.show("设置成功");
//                    manager.readAllUserAccountInfo()
//                    Lismanager.readAllUserAccountInfo()
                    finish();
                    Intent intent = new Intent(ForgetFindActivity.this,LoginAccountActivity.class);
                    intent.putExtra("fromRegist",true);
                    startActivity(intent);
                }
            });
        }
    }

    @OnClick(R.id.actvity_back)
    public void gotoRegist(View view){
        finish();
    }

}
